Previous | Home | Next |
Tag description: JSF<f:setPropertyActionListener> Tag is register an ActionListener instance on the UIComponent associate with the enclosing parent tag.
Tag is use to set the "Value" form value attribute to be set into the ValueExpression given by the "target" attribute.
Example:
Step 1: Welcome page of Example
<%-- Name= welcomeJSF.jsp --%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%> <%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%> <!DOCTYPE HTML PUBLIC " -//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org /TR/html4/loose.dtd"> <%-- This file is an entry point for JavaServer Faces application. --%> <f:view> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <title>r4r.co.in</title> </head> <body> <h1><h:outputText value="Tag <f:setPropertyActionListener> Example"/></h1> <h:form> <h:commandLink value="Click Me" action="#{setProperty.submit()}" > <%-- Tag <f:setPropertyActionListener> use --%> <f:setPropertyActionListener target="#{setProperty.name}" value="r4r tech soft" /> </h:commandLink> <Br><BR> <h:panelGrid rendered="#{setProperty.flag!= false}"> Value from setPropertyActionListener: <h:outputText value="#{setProperty.name}" /> </h:panelGrid> </h:form> </body> </html> </f:view>
Step 2: ManagedBean class for provide logic in program.
/* * Save as a setPropertyActionListenerBean.java */ package r4r.JSF2; import javax.faces.bean.ManagedBean; import javax.faces.bean.RequestScoped; @ManagedBean(name = "setProperty") @RequestScoped public class setPropertyActionListenerBean { private String name; private boolean flag = false; /* -- Getter/Setter -- */ public boolean isFlag() { return flag; } public void setFlag(boolean flag) { this.flag = flag; } public String getName() { return name; } public void setName(String name) { this.name = name; } /* -- submit method -- */ public String submit() { flag = true; return "submit"; } }
Output:
Previous | Home | Next |